package fields;
import boundaryToMatador.GUI;
import game.Player;

public class Territory extends Ownable {

	public int rent;
	public int payPrice;
	public int housesBuilt;
	public boolean isHotelBuilt;
	public int houseCost;
	
	public int rent1house;
	public int rent2house;
	public int rent3house;
	public int rent4house;
	public int rentHotell;
	
	public Territory (int number, String name, int price, int rent, int rent1house, int rent2house, int rent3house, int rent4house, int rentHotell){
		
		super (number, name, price); 
		fieldValue=1;
		this.rent = rent;
		this.rent1house=rent1house;
		this.rent2house=rent2house;
		this.rent3house=rent3house;
		this.rent4house=rent4house;
		this.housesBuilt=0;
		this.isHotelBuilt=false;
	
	
	if (number < 11) {
			this.houseCost = 50;
		} else if (number < 21) {
		this.houseCost = 100;
		} else if (number < 31) {
		this.houseCost = 150;
		} else {
		this.houseCost = 200;
		}

	}
	public int getHouseCost() {
		return this.houseCost;
	}
	
	public boolean isHotelBuilt(){
		return this.isHotelBuilt;
	}
	public int housesBuilt(){
		return this.housesBuilt;
	}
	
	public void landOnField(Player sp)
	{
		if (!isNotOwned() && sp!=owner)
		{
			sp.transfer(getRent(), owner);
		}
		else {
			if (sp.getChoice()==1) buy(sp);
		}
		
	}
	
	public int getRent() {
		
			if (this.isHotelBuilt) {
				return this.rentHotell;
			
		} else {
			switch (this.housesBuilt){
			case 1: return this.rent1house;
			case 2: return this.rent2house;
			case 3: return this.rent3house;
			case 4: return this.rent4house;
			default: return this.rent;
			}
		}
	}
	
	public void setRent(int rent) {
		this.rent = rent;
			}
	
	public int getPayPrice() {
		return payPrice;
	}
		
	public void buy(Player s)
	{
		super.buy(s);
		s.addTerritory(this);;
	}	
	
	public boolean canBuild() {
		return !this.isHotelBuilt;
			}
			public void build() {
				if (!this.isHotelBuilt) {
					this.housesBuilt++;
						if (this.housesBuilt>4) {
							GUI.setHotel(this.fieldNumber+1, true);
							this.housesBuilt = 0;
							this.isHotelBuilt = true;
						} else {
					GUI.setHouses(this.fieldNumber+1, this.housesBuilt);
						}
		}
				
			}
			public void sellHouse() {
				if (this.housesBuilt>0) {
					this.housesBuilt--;
					GUI.setHouses(this.fieldNumber+1, this.housesBuilt);
				} else if(this.isHotelBuilt){
					this.isHotelBuilt = false;
					this.housesBuilt=4;
					GUI.setHotel(this.fieldNumber+1, false);
					GUI.setHouses(this.fieldNumber+1, this.housesBuilt);
				}
				}
			}
